package com.lemt.mall.controller;

import com.lemt.common.result.Res;
import com.lemt.mall.entity.Inventory;
import com.lemt.mall.mapper.InventoryMapper;
import com.lemt.mall.service.IInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zik
 * @since 2023-09-10
 */
@Api(tags = "库存管理")
@Slf4j
@RestController
@RequestMapping("/mall/inventory")
public class InventoryController {

    @Resource
    private IInventoryService inventoryService;


    @ApiOperation("保存库存")
    @PostMapping("/saveInventory")
    public Res<Boolean> saveInventory(Inventory inventory){
        log.info("{}",inventory);
        return Res.ok(inventoryService.save(inventory));
    }

    @ApiOperation("删除库存")
    @DeleteMapping("/removeInventory")
    public Res<Boolean> removeInventory(@RequestBody Inventory inventory){
        log.info("{}",inventory);
        return Res.ok(inventoryService.removeById(inventory));
    }

    @ApiOperation("修改库存")
    @PostMapping("/updateInventory")
    public Res<Boolean> updateInventory(@RequestBody Inventory inventory) {
        log.info("{}",inventory);
        return Res.ok(inventoryService.updateById(inventory));
    }

    @ApiOperation("根据goodsId获取库存")
    @GetMapping("/getByGoodsId/{id}")
    public Res<List<Inventory>> getByGoodsId(@PathVariable Integer id){
        return Res.ok(inventoryService.getByGoodsId(id));
    }


}
